import java.awt.*;

   import java.awt.event.*;

import javax.swing.*;

 

    public class PigLatinPanel extends JPanel

   {

      private JTextField sentence;

      private JLabel label;
      
      private JLabel translation;
      
      private PigLatinTranslator plt;

    
       public PigLatinPanel ()

      {

    	   setLayout(new BorderLayout());
    	   
    	   JToolBar toolBar = new JToolBar();
    	   
         sentence = new JTextField ();
         sentence.setPreferredSize(new Dimension(150, 25));
         
         sentence.addActionListener (new JTextFieldListener());  

         label = new JLabel ("Please enter a word");

       translation = new JLabel();
       translation.setHorizontalAlignment(SwingConstants.CENTER);
//       translation.setVerticalAlignment(SwingConstants.TOP);

         toolBar.add (label);
         toolBar.add (sentence);
         add(toolBar, BorderLayout.NORTH);
         
         add (translation, BorderLayout.CENTER);


       

         setPreferredSize (new Dimension(800,800));

         setBackground (Color.green);
         
         plt = new PigLatinTranslator();

      }

    

       private class JTextFieldListener implements ActionListener

      {

          public void actionPerformed (ActionEvent event)

          { 

            String text = sentence.getText();
            
            System.out.println("Sentence:" + text);
            
            String pgTranslation = plt.translate(text);
          
            System.out.println("Translation:" + pgTranslation);
             
            translation.setText(pgTranslation);

          }
      }
   }

      

    

    
